import {createRouter, createWebHashHistory} from "vue-router";
import Index from "@/layout/index.vue";
import NProgress from 'nprogress';

const routes = [
    {
        path: "/",
        name: "首页",
        component: Index,
        redirect: "/dashboard/analysis",
        children: [
            {
                path: "dashboard/analysis",
                name: "分析页",
                component: () => import("@/views/dashboard/analysis.vue"),
            },
        ]
    },
    {
        path: "/system",
        name: "系统管理",
        component: Index,
        children: [
            {
                path: "account",
                name: "用户管理",
                component: () => import("@/views/system/user/user.vue"),
            },
            {
                path: "menu",
                name: "菜单管理",
                component: () => import("@/views/system/menu/menu.vue"),
            },
            {
                path: "role",
                name: "角色管理",
                component: () => import("@/views/system/role/role.vue"),
            },
            {
                path: "dept",
                name: "部门管理",
                component: () => import("@/views/system/dept/dept.vue"),
            },
            {
                path: "post",
                name: "岗位管理",
                component: () => import("@/views/system/post/post.vue"),
            },
        ]
    },
    {
        path: "/monitor",
        name: "日志管理",
        component: Index,
        children: [
            {
                path: "login_log",
                name: "登录日志",
                component: () => import("@/views/log/login_log/login_log.vue"),
            },
            {
                path: "operation_log",
                name: "操作日志",
                component: () => import("@/views/log/operation_log/operation_log.vue"),
            },
            {
                path: "error_log",
                name: "异常日志",
                component: () => import("@/views/log/error_log/error_log.vue"),
            },
        ]
    },
    {
        path: "/setting",
        name: "系统设置",
        component: Index,
        children: [
            {
                path: "center",
                name: "个人中心",
                component: () => import("@/views/setting/center/center.vue"),
            }
        ]
    },
    {
        path: "/login",
        name: "登录",
        component: () => import("@/views/login/login.vue"),
    },
    {
        path: "/:pathMatch(.*)",
        name: "NotFound",
        component: () => import("@/components/not-found/NotFound.vue"),
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    NProgress.start();
    next();
});

router.afterEach(() => {
    NProgress.done();
})

export default router;